WAFER_DIR := ../../..
WAFER_BUILD_DIR = $(WAFER_DIR)/build
WAFER_FRONTEND := ${WAFER_BUILD_DIR}/bin/wafer-frontend
CLANG := ${WAFER_DIR}/3rdparty/llvm/build/bin/clang++
INCLUDE := /usr/lib/gcc/x86_64-linux-gnu/11/include

export sha1_CGRA_SIM_PATH=/home/caohanghang/gitproject/wafer-compiler/3rdparty/sim_app/sim_convert/algo_rpulog/sha1/rpu_solution/sha1/sha1

export sm3_CGRA_SIM_PATH=/home/caohanghang/gitproject/wafer-compiler/3rdparty/sim_app/sim_convert/algo_rpulog/sm3/rpu_solution/sm3/sm3

export md5_CGRA_SIM_PATH=/home/caohanghang/gitproject/wafer-compiler/3rdparty/sim_app/sim_convert/algo_rpulog/MD5/rpu_solution/md5_FM/md5_FM

export SIMULATOR_CTRL=/home/caohanghang/gitproject/wafer-compiler/3rdparty/sim_app/sim_ide/bin/simulator_ctrl

sha1:
	make TARGET="sha1" sha1.out

md5:
	make TARGET="md5" md5.out

sm3:
	make TARGET="sm3" sm3.out

$(TARGET).out: $(TARGET)_op.o $(TARGET).o
	$(CLANG) $^ \
	-L$(WAFER_BUILD_DIR)/lib/CGRAAPI -lwafer_cgra_api \
	-o $@

$(TARGET)_op.o: $(TARGET)_op.ll
	$(CLANG) -c $< -o $@

$(TARGET)_op.ll: $(TARGET).cpp
	${WAFER_FRONTEND} $< -I ${INCLUDE} --lower-crypto-to-cgra --wafer-to-llvmir -o $@

$(TARGET).o: $(TARGET).cpp
	@${CLANG} -c $< -I ${INCLUDE} -o $@

.PHONY: clean
clean:
	rm -rf *.out *.ll *.mlir *.s *cubin *fatbin *.o *.txt
